package com.cxg.fairy.ec.main.personal.coupon;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cxg.fairy.ui.recycler.MultipleItemEntity;

import com.cxg.fairy.ui.recycler.DataConverter;

import java.util.ArrayList;

/**
 * Created by Administrator on 2018/3/8.
 */

    public class CouponListDataConverter extends DataConverter {

        @Override
        public ArrayList<MultipleItemEntity> convert() {
            final JSONArray array = JSON.parseObject(getJsonData()).getJSONArray("data");
            final int size = array.size();
            for (int i = 0; i < size; i++) {

                final JSONObject data = array.getJSONObject(i);
                final int id = data.getInteger("couponGetId");
                final String coupon_no = data.getString("coupon_no");
                final String coupon_name = data.getString("coupon_name");
                final String coupon_status = data.getString("coupon_status");
                final String coupon_time = data.getString("coupon_time");
                final String coupon_desc = data.getString("coupon_desc");

                final MultipleItemEntity entity = MultipleItemEntity.builder()
                        .setItemType(CouponItemType.COUPON_ITEM)
                        .setField(CouponItemFields.ID, id)
                        .setField(CouponItemFields.COUPON_NO, coupon_no)
                        .setField(CouponItemFields.COUPON_NAME, coupon_name)
                        .setField(CouponItemFields.COUPON_STATUS, coupon_status)
                        .setField(CouponItemFields.COUPON_VALID_TIME, coupon_time)
                        .setField(CouponItemFields.COUPON_DESC, coupon_desc)
                        .build();
                ENTITIES.add(entity);
            }
            return ENTITIES;
        }

    @Override
    public MultipleItemEntity convertHeader() {
        return null;
    }


}
